package cn.com.huzo.repository.purchase.impl;

import cn.com.huzo.model.entities.purchase.NotesPayabledLinesEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import cn.com.huzo.repository.purchase.NotesPayabledLinesRepository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 对账单明细数据访问对象。
 *
 * @author 吴旭
 */
@Repository("NotesPayabledLinesRepository")
public class NotesPayabledLinesRepositoryImpl extends GenericRepositoryImpl<NotesPayabledLinesEntity, String>
        implements NotesPayabledLinesRepository {

    private final String namespace = "cn.com.huzo.repository.purchase.NotesPayabledLinesRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public NotesPayabledLinesRepositoryImpl() {
        super(NotesPayabledLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<NotesPayabledLinesEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insert(Map<String, Object> criterion) {
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(namespace,
                "insert"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<NotesPayabledLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer deleteByPoStackInLinesId(String poStockInLinesId) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "deleteByPoStackInLinesId"), poStockInLinesId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchDelete(List<NotesPayabledLinesEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchDelete"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Double fetchTotalAmount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchTotalAmount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<NotesPayabledLinesEntity> fetchExportLinesData(Long headerId, Integer styleNoFlag) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("StyleNoFlag", styleNoFlag);

        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchExportLinesData"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<NotesPayabledLinesEntity> fetchExportLinesDataWithStyleNo(Long headerId, Integer styleNoFlag) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("StyleNoFlag", styleNoFlag);

        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchExportLinesDataWithStyleNo"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<Map<String, Object>> fetchLateArrivalCutPayabledAmount(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchLateArrivalCutPayabledAmount"), criterion);
    }
}
